package com.lmaye.cloud.core.exception;

import cn.hutool.core.util.StrUtil;
import com.lmaye.cloud.core.context.IResultCode;
import lombok.Getter;

/**
 * -- 通用自定义异常
 *
 * @author lmay.Zhou
 * @email lmay@lmaye.com
 * @since 2020-12-01 15:23:22
 */
@Getter
public class CoreException extends RuntimeException {

    private final IResultCode resultCode;

    public CoreException(IResultCode resultCode) {
        super(resultCode.getDesc());
        this.resultCode = resultCode;
    }

    public CoreException(IResultCode resultCode, String message) {
        super(StrUtil.format(resultCode.getDesc(), message));
        this.resultCode = resultCode;
    }

    public CoreException(IResultCode resultCode, Throwable cause) {
        super(resultCode.getDesc(), cause);
        this.resultCode = resultCode;
    }

    public CoreException(IResultCode resultCode, Throwable cause, String message) {
        super(StrUtil.format(resultCode.getDesc(), message), cause);
        this.resultCode = resultCode;
    }
}
